package com.gastudio.Basic;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by 余艾龙 on 2017/6/20.
 */
public class MyClientHandler extends IoHandlerAdapter {
    //使用SLF4J做日志记录器
    private final static Logger log= LoggerFactory.getLogger(MyServerHandler.class);

    private final String SendMessage;

    public MyClientHandler(String sendMessage) {
        SendMessage = sendMessage;
    }

    @Override
    public void exceptionCaught(IoSession ioSession, Throwable throwable) throws Exception {
        System.out.println("程序异常");
    }

    @Override
    public void messageReceived(IoSession ioSession, Object o) throws Exception {
        String msg=(String)o;
        System.out.println("收到数据:"+msg);
    }

    @Override
    public void sessionOpened(IoSession session) throws Exception {
        session.write(SendMessage);
    }
}
